<template>
	<view class="container">
		<scroll-view scroll-y class="list" v-if="list.length!=0" @scrolltolower="loadMore">
			<view class="list_item" @click="toDetail(item.order_sn)" v-for="(item,index) in list" :key="item.id">
				<view class="left">
					<view class="img">
						<image src="/static/img/detail/Battery.png" mode="widthFix"></image>
					</view>
					<view class="item_l">
						<text>使用{{item.use_time}}
						</text>
						<text class="time">
							<text v-if="item.is_pay == 1">已支付-{{orderPayType(item)}} <text
									v-if="item.remark">-{{item.remark}}</text> </text>
							<text v-else-if="item.is_pay ==0">未支付</text></text>
						<text class="time">{{item.start_time_date}}</text>
					</view>
				</view>
				<view class="item_r">
					<view>订单金额:￥{{item.pay_money}}</view>
					<view v-if="item.actual_money">实际支付:￥{{item.actual_money}}</view>
				</view>
			</view>
		</scroll-view>

		<view class="list" v-else>
			<view class="empty">
				暂无记录
			</view>
		</view>
	</view>
</template>

<script>
	import {
		orderList
	} from '../../../api/api.js'
	export default {
		data() {
			return {
				// key: value
				list: [],
				total: 0,
				last_page: 1,
				current_page: 1,
				per_page: 15
			}
		},
		onLoad() {

		},
		onShow() {
			this.current_page = 1
			this.getList()
		},
		methods: {
			orderPayType(item) {
				if (item.pay_type == 0) {
					return '微信'
				} else if (item.pay_type == 1) {
					return '支付宝'
				} else if (item.pay_type == 2) {
					return '余额'
				} else if (item.pay_type == 4) {
					return '免单券'
				} else if (item.pay_type == 5) {
					return '折扣券'
				} else if (item.pay_type == 6) {
					return '次卡'
				} else {
					return '未知'
				}
			},
			toDetail(order_sn) {
				uni.navigateTo({
					url: '/pages/detail/detail?order_sn=' + order_sn
				})
			},
			getList(loadMore) {
				orderList({
					limit: this.per_page,
					page: this.current_page
				}).then(res => {
					if (loadMore) {
						for (let i = 0; i < res.data.data.length; i++) {
							this.list.push(res.data.data[i])
						}
					} else {
						this.list = res.data.data
					}
					this.total = res.data.total
					this.last_page = res.data.last_page
					this.current_page = res.data.current_page
				})
			},
			loadMore(e) {
				if (this.current_page < this.last_page) {
					this.current_page += 1
					this.getList('loadMore')
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.container {
		width: 100%;
		padding-top: 10upx;
		height: 100%;
		background-color: #f6f6f6;
	}

	.list {
		width: 100%;
		height: 98%;
		background-color: #FFFFFF;

		.list_item {
			width: calc(100% - 60upx);
			padding: 10upx 0;
			height: 100upx;
			margin: 0 auto;
			display: flex;
			justify-content: space-between;
			align-items: center;
			border-bottom: 1upx solid #f7f7f7;

			.left {
				display: flex;
				align-items: center;

				.img {
					width: 80upx;
					height: 80upx;
					background-color: #D8EFFF;
					border-radius: 50%;
					display: flex;
					align-items: center;
					justify-content: center;
					margin-right: 20upx;

					image {
						width: 50upx;
					}
				}

				.item_l {
					height: 80%;
					display: flex;
					font-size: 28upx;
					flex-direction: column;
					justify-content: space-around;

					.time {
						color: #999999;
						font-size: 24upx;
					}
				}
			}



			.item_r {
				color: #25a0e6;
				display: flex;
				font-size: 28upx;
				flex-direction: column;
				justify-content: space-around;
			}
		}

		.empty {
			width: calc(100% - 60upx);
			height: 100upx;
			text-align: center;
			line-height: 100upx;
		}
	}
</style>